#include<iostream>
#include<string>
#include<string.h>
#include<ctime>
#include<unistd.h>
#include<pthread.h>
#include<stdio.h>
using namespace std;

//测试死锁问题
//不同的线程也可以解同一把锁

pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER;

void* threadRun(void * args)
{
    
    pthread_mutex_lock(&mutex);

    cout<<"申请锁"<<endl;

    pthread_mutex_lock(&mutex);
    cout<<"2次申请锁"<<endl;

    return nullptr;
}



int main()
{
    pthread_t tid;

    pthread_create(&tid,nullptr,threadRun,nullptr);

    sleep(2);
    pthread_mutex_unlock(&mutex);
    cout<<"主函数解锁"<<endl;


    return 0;
}